#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5e5 + 5;

int n, m;
int a[N];
struct Node {
  int mxl, mxr, mx, sum;
} tr[N << 2];
Node merge(Node x, Node y) {
  Node res;
  res.mxl = max(x.mxl, x.sum + y.mxl);
  res.mxr = max(y.mxr, y.sum + x.mxr);
  res.mx = max({x.mx, y.mx, x.mxr + y.mxl});
  res.sum = x.sum + y.sum;
  return res;
}
void build(int p, int l, int r) {
  if (l == r) {
    tr[p].mx = tr[p].mxl = tr[p].mxr = tr[p].sum = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  tr[p] = merge(tr[p << 1], tr[p << 1 | 1]);
}
void update(int x, int v, int p, int l, int r) {
  if (l == r) {
    tr[p].mx = tr[p].mxl = tr[p].mxr = tr[p].sum = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, v, p << 1, l, mid);
  else
    update(x, v, p << 1 | 1, mid + 1, r);
  tr[p] = merge(tr[p << 1], tr[p << 1 | 1]);
}
Node query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return tr[p];
  int mid = (l + r) >> 1;
  if (R <= mid)
    return query(L, R, p << 1, l, mid);
  else if (L > mid)
    return query(L, R, p << 1 | 1, mid + 1, r);
  else {
    Node x = query(L, R, p << 1, l, mid);
    Node y = query(L, R, p << 1 | 1, mid + 1, r);
    return merge(x, y);
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  build(1, 1, n);
  while (m--) {
    int op, x, y;
    cin >> op >> x >> y;
    if (op == 1) {
      if (x > y) swap(x, y);
      cout << query(x, y, 1, 1, n).mx << endl;
    } else
      update(x, y, 1, 1, n);
  }
  return 0;
}